<!DOCTYPE html>

<html lang='en'>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./lib/react.development16.4.0.js"></script>
    <script src="./lib/react-dom.development16.4.0.js"></script>
    <script src="./lib/babel.min.js"></script>
</head>

<body>
    <div id="app">
    </div>
    <script type="text/babel">
       class Button extends React.Component {
            constructor(props) {
                super(props);
                this.state = {data: 0};
                this.setNewNumber = this.setNewNumber.bind(this);
            }
            
            setNewNumber() {
                this.setState({data: this.state.data + 1})
            }
            render() {
                return (
                    <div>
                        <button onClick = {this.setNewNumber}>INCREMENT</button>
                        <Content myNumber = {this.state.data}></Content>
                    </div>
                );
                }
            }
            
            
        class Content extends React.Component {
            componentWillMount() {
                console.log('准备渲染前!')
            }
            componentDidMount() {
                console.log('渲染完成!调用render')
            }
            componentWillReceiveProps(newProps) {
                    console.log('更新props属性值!')
            }
            shouldComponentUpdate(newProps, newState) {
                    console.log("更新props或者state之前，返回true或者false")
                    return true;
            }
            componentWillUpdate(nextProps, nextState) {
                    console.log('"更新props或者state之后!');
            }
            componentDidUpdate(prevProps, prevState) {
                    console.log('更新完毕！!')
            }
            componentWillUnmount() {
                    console.log('组件销毁!')
            }
            
            render() {
                return (
                    <div>
                    <h3>{this.props.myNumber}</h3>
                    </div>
                );
                }
            }
            ReactDOM.render(
            <div>
                <Button />
            </div>,
            document.getElementById('app')
            );
       
    </script>
</body>

</html>